package com.vivz.guess.what;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;

public class AboutActivity extends Activity {

	// //////////////////
	// Screen Elements
	// //////////////////

	private WebView webView;

	@Override
	public void onCreate(final Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_about);

		webView = (WebView) findViewById(R.id.about_web_view);
		webView.getSettings().setJavaScriptEnabled(true);
		// webView.loadUrl("http://www.google.com");
		// loadDataWithBaseURL("file:///android_asset/web/", html, "text/html", "UTF-8", null);
		webView.loadDataWithBaseURL("file:///android_asset/", getHtmlFromAsset(), "text/html", "UTF-8", null);

	}

	/**
	 * Gets html content from the assets folder.
	 */
	private String getHtmlFromAsset() {
		final StringBuilder builder = new StringBuilder();

		try {
			final InputStream is = getAssets().open(getString(R.string.index_html));
			if (is != null) {
				final BufferedReader reader = new BufferedReader(new InputStreamReader(is));
				String line;
				while ((line = reader.readLine()) != null) {
					builder.append(line);
				}
			}
		} catch (final IOException e) {
			e.printStackTrace();
		}

		return builder.toString();
	}
}
